package com.xywy.common.net;

import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.provider.Settings;
import com.xywy.R;

/**
 * 提示信息的管理
 */

public class PromptManager {
    private static ProgressDialog dialog;

    public static void showProgressDialog(Context context) {
        dialog = new ProgressDialog(context);
        dialog.setTitle(R.string.app_name);
        dialog.setMessage("请等候，数据加载中……");
        dialog.show();
    }

    public static void closeProgressDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /**
     * 当判断当前手机没有网络时使用
     *
     * @param context
     */
    public static void showNoNetWork(final Context context) {
        Builder builder = new Builder(context);
        builder.setTitle(R.string.app_name)//
                .setMessage("当前无网络")
                .setPositiveButton("设置", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 跳转到系统的网络设置界面
                        Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
//                        intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
                        context.startActivity(intent);

                    }
                }).setNegativeButton("知道了", null).show();
    }

    /**
     * 退出系统
     *
     * @param context
     */
    public static void showExitSystem(Context context) {
        Builder builder = new Builder(context);
        builder.setTitle(R.string.app_name)//
                .setMessage("是否退出应用")
                .setPositiveButton("确定", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        android.os.Process.killProcess(android.os.Process.myPid());
                        //多个Activity——懒人听书：没有彻底退出应用
                        //将所有用到的Activity都存起来，获取全部，干掉
                        //BaseActivity——onCreated——放到容器中
                    }
                })
                .setNegativeButton("取消", null)//
                .show();

    }

    /**
     * 显示错误提示框
     *
     * @param context
     * @param msg
     */
    public static void showErrorDialog(Context context, String msg) {
        new Builder(context)//
                .setTitle(R.string.app_name)//
                .setMessage(msg)//
                .setNegativeButton("ok", null)//
                .show();
    }
}
